#pragma once

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include<boost/algorithm/string.hpp>
// #include"cppjieba/Jieba.hpp"
#include"cppjieba/Jieba.hpp"
namespace ns_util
{
    class FileUtil
    {
        public:
            static bool ReadFile(const std::string& file_path,std::string*out)
            {
                std::ifstream in(file_path, std::ios::in);  // 显式指定读取模式
                // std::ifstream in(file_path);                // 隐式使用默认的读取模式
                if(!in.is_open())
                {
                    std::cerr<<"open file "<<file_path<<" error "<<std::endl;
                    return false;
                }
                std::string line;
                while(getline(in,line))
                {
                    *out+=line;
                }
                in.close();
                return true;
            }
    };

    class StringUtil
    {
    public:
        static bool Split(const std::string&line,std::vector<std::string>*result,const std::string&sep)//把解析后的，切分字符串
        {
            //boost库切字符串，result类型是std::vector<std::string>，用于存放切割之后的字符串
            boost::split(*result,line,boost::is_any_of(sep),boost::token_compress_on);
            return true;
        }
    };
    
    const char* const DICT_PATH = "./dict/jieba.dict.utf8";
    const char* const HMM_PATH = "./dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char* const IDF_PATH = "./dict/idf.utf8";
    const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";

    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;
    public:
         static void CutString(const std::string &src, std::vector<std::string> *out)
            {
                // ns_util::JiebaUtil::get_instance()->CutStringHelper(src, out);
                jieba.CutForSearch(src, *out);
            }
    };
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);
}